<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>PHP Arrays</title>
</head>
<body>
<h1>PHP Arrays</h1>
<div>
    <h3>PHP Indexed Arrays</h3>
    <?php
    /*There are two ways to create indexed arrays:
    The index can be assigned automatically (index always starts at 0):*/
    $cars = array("Volvo","BMW","Toyota");
//  or the index can be assigned manually:
    $cars[0] = "Volvo";
    $cars[1] = "BMW";
    $cars[2] = "Toyota";
    echo("I like".$cars[0].", ".$cars[1].", ".$cars[2]);
    ?>
</div>
<div>
    <h3>Get The length of an Array - The count() Function</h3>
    <?php
    echo(count($cars));
    ?>
</div>
<div>
    <h3>Loop Through an Indexed Array</h3>
    <?php
    $arrlength = count($cars);
    for($x=0;$x<$arrlength;$x++){
        echo($cars[$x]);
        echo("<br/>");
    }
    ?>
</div>
<div>
    <h3>PHP Associative Arrays</h3>
    <?php
    //There are two ways to create an associative array:
    $age = array("Peter"=>"35","Ben"=>"37","Joe"=>"43");
    //or
    $age['Peter']="35";
    $age['Ben']="37";
    $age['Joe']="43";
    echo("Peter is ".$age['Peter']." years old.");
    ?>
</div>
<div>
    <h3>Loop Through an Associative Array</h3>
    <?php
    foreach ($age as $x=>$x_value){
        echo("Key=".$x.", Value=".$x_value);
        echo("<br/>");
    }
    ?>
</div>
</body>
</html>